package com.kgcx.coupon.controller;

import com.kgcx.common.bean.RequestData;
import com.kgcx.common.bean.ReturnData;
import com.kgcx.common.controller.BaseController;
import com.kgcx.coupon.domain.RatedDriver;
import com.kgcx.coupon.service.RatedDriverService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

/**
 * @author zhulong
 */
@Api(description = "司机信誉", tags = "司机信誉接口")
@RestController
@RequestMapping("rated")
public class RatedDriverController extends BaseController {

    @Autowired
    private RatedDriverService ratedDriverService;

    @ApiOperation(value = "驾驶员信誉", httpMethod = "POST", notes = "这是发起对某个驾驶员信誉评定的接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "licenseId", value = "驾驶证编号", required = true, paramType = "query", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "level", value = "服务质量信誉等级", required = true, paramType = "query", dataType = "float", dataTypeClass = Float.class),
            @ApiImplicitParam(name = "testDepartment", value = "服务质量信誉考核机构", required = true, paramType = "query", dataType = "String", dataTypeClass = String.class)

    })
    @PostMapping("addRated")
    public ReturnData<Integer> addRatedDriver(String licenseId,Float level, String testDepartment) {
        ReturnData<Integer> returnData = ReturnData.getResult();
        Integer one = ratedDriverService.addRatedDriver(licenseId,level,testDepartment);
        returnData.setData(one);
        return returnData;
    }


    @ApiOperation(value = "驾驶员信誉", httpMethod = "POST", notes = "这是发起对某个驾驶员信誉评定的接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "licenseId", value = "驾驶证编号", required = true, paramType = "query", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "level", value = "服务质量信誉等级", required = false, paramType = "query", dataType = "float", dataTypeClass = Float.class),
            @ApiImplicitParam(name = "testDepartment", value = "服务质量信誉考核机构", required = false, paramType = "query", dataType = "String", dataTypeClass = String.class)

    })
    @PostMapping("updateRated")
    public ReturnData<Integer> updateRatedDriver(String licenseId,Float level, String testDepartment) {
        ReturnData<Integer> returnData = ReturnData.getResult();
        Integer num = ratedDriverService.existDriver(licenseId);
        if (num.intValue() == 0){
            returnData.setCode("-1");
            returnData.setMsg("该驾驶证编号数据不存在，请先新增");
            return returnData;
        }
        Integer one = ratedDriverService.updateRatedDriver(licenseId,level,testDepartment);
        returnData.setData(one);
        return returnData;
    }



    @ApiOperation(value = "根据驾驶证编号查询服务等级", httpMethod = "POST", notes = "这是前台查询服务等级接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "licenseId", value = "驾驶证编号", required = true, paramType = "query", dataType = "String", dataTypeClass = String.class),
    })
    @PostMapping("findLevelByLicenseId")
    public ReturnData<Float> findLevelByLicenseId(String licenseId) {
        ReturnData<Float> returnData = ReturnData.getResult();
        Float num = ratedDriverService.selectLevelByLicenseId(licenseId);
        returnData.setData(num);
        return returnData;
    }
    /**
     * 专给监管平台提供查询
     */
    @ApiOperation(value = "监管平台查询司机信誉信息", httpMethod = "GET", notes = "这是用来给监管平台查询司机信誉信息的接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", required = false, paramType = "query", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "pageSize", value = "页容量", required = false, paramType = "query", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "orderBy", value = "排序,sql格式", required = false, paramType = "query", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "kid", value = "主键ID", required = false, paramType = "query", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "licenseId", value = "驾驶证号", required = false, paramType = "query", dataType = "String", dataTypeClass = String.class)
    })
    @GetMapping("queryRatedDriverWithPage")
    public ReturnData<List<RatedDriver>> queryRatedDriverWithPage() {
        RequestData rd = this.getRequestData();
        List<RatedDriver> rdDriverList = ratedDriverService.queryRatedDriverWithPage(rd);
        return new ReturnData<>(rdDriverList);
    }
}
